class DataFeed {
  constructor (symbolInfoList, getHistoryData, subscribe, unsubscribe) {
    this.symbolInfoList = symbolInfoList
    this.getHistoryData = getHistoryData
    this.subscribe = subscribe
    this.unsubscribe = unsubscribe
    this.symbolInfo = null
    this.resolution = '1'
  }

  onReady (cb) {
    setTimeout(() => {
      /* eslint-disable */
      cb({
        supported_resolutions: [
          1, 3, 5, 15, 30, 60, 120, 240, 360, 720, 'D', 'W', 'M'
        ],
        supports_marks: false,
        supports_timescale_marks: false,
        supports_time: true
      })
    }, 0)
  }

  resolveSymbol (symbolName, onSymbolResolvedCallback, onResolveErrorCallback) {
    const symbolInfo = this.symbolInfoList.find(data => data.name === symbolName)
    this.symbolInfo = { ...symbolInfo }
    onSymbolResolvedCallback({
      ...symbolInfo,
      has_intraday: true,
      has_weekly_and_monthly: true
    })
  }

  getBars (symbolInfo, resolution, from, to, onHistoryCallback, onErrorCallback, firstDataRequest) {
    this.getHistoryData(symbolInfo, resolution, from, to, onHistoryCallback, onErrorCallback, firstDataRequest)
  }

  subscribeBars (symbolInfo, resolution, onRealtimeCallback, subscriberUID, onResetCacheNeededCallback) {
    this.resolution = resolution
    this.subscribe(symbolInfo.ticker, symbolInfo.exchangeId, resolution, onRealtimeCallback)
  }

  unsubscribeBars (subscriberUID) {
    this.unsubscribe(this.symbolInfo.ticker, this.symbolInfo.exchangeId, this.resolution)
  }
}

export default DataFeed
